﻿using System.Data;
using ContractManagementSystem.DataAccess;
using ContractManagementSystem.Entity;

namespace ContractManagementSystem.BusinessLogic
{
    public static class ContractorBusiness
    {
        public static string ErrorMessage { get; set; }
        private static ContractorDataAccess _contractorDataAccess;

        /// <summary>
        /// Function Select All Contractor
        /// Author: Group2.DucDM
        /// </summary>
        /// <param name="activeType"></param>
        /// <returns></returns>
        public static DataTable FetchAll(int activeType)
        {
            _contractorDataAccess = new ContractorDataAccess();
            if (_contractorDataAccess.FetchAll(activeType) == null)
            {
                ErrorMessage = _contractorDataAccess.ErrorMessage;
            }
            return _contractorDataAccess.FetchAll(activeType);
        }

        /// <summary>
        /// Function Select Contractor By Role
        /// Author: Group2.DucDM
        /// </summary>
        /// <param name="userRole"> </param>
        /// <param name="userName"></param>
        /// <returns></returns>
        public static DataTable FetchByRole(string userRole, string userName)
        {
            _contractorDataAccess = new ContractorDataAccess();
            if (_contractorDataAccess.FetchByRole(userRole,userName) == null)
            {
                ErrorMessage = _contractorDataAccess.ErrorMessage;
            }
            return _contractorDataAccess.FetchByRole(userRole,userName);
        }

        /// <summary>
        /// Function SearchFullName
        /// Author: Group2.DucDM
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static DataTable SearchFullName(string name)
        {
            _contractorDataAccess = new ContractorDataAccess();
            if (_contractorDataAccess.SearchFullName(name) == null)
            {
                ErrorMessage = _contractorDataAccess.ErrorMessage;
            }
            return _contractorDataAccess.SearchFullName(name);
        }

        /// <summary>
        /// Function SearchByRole
        /// Author: Group2.DucDM
        /// </summary>
        /// <param name="name"></param>
        /// <param name="nameUser"> </param>
        /// <returns></returns>
        public static DataTable SearchByRole(string name, string nameUser)
        {
            _contractorDataAccess = new ContractorDataAccess();
            if (_contractorDataAccess.SearchByRole(name, nameUser) == null)
            {
                ErrorMessage = _contractorDataAccess.ErrorMessage;
            }
            return _contractorDataAccess.SearchByRole(name, nameUser);
        }

        /// <summary>
        /// Function Select By Id Contractor
        /// Author: Group2.DucDM
        /// </summary>
        /// <param name="contractorEntity"></param>
        /// <returns></returns>
        public static DataTable FetchById(ContractorEntity contractorEntity)
        {
            _contractorDataAccess = new ContractorDataAccess();
            if (_contractorDataAccess.FetchById(contractorEntity) == null)
            {
                ErrorMessage = _contractorDataAccess.ErrorMessage;
            }
            return _contractorDataAccess.FetchById(contractorEntity);
        }

        /// <summary>
        /// Function Insert Contractor
        /// Author: Group2.DucDM
        /// </summary>
        /// <param name="contractorEntity"></param>
        /// <returns></returns>
        public static bool Insert(ContractorEntity contractorEntity)
        {
            _contractorDataAccess = new ContractorDataAccess();
            if (_contractorDataAccess.Insert(contractorEntity))
            {
                return true;
            }
            ErrorMessage = _contractorDataAccess.ErrorMessage;
            return false;
        }

        /// <summary>
        /// Function Update Contractor
        /// Author: Group2.DucDM
        /// </summary>
        /// <param name="contractorEntity"></param>
        /// <returns></returns>
        public static bool Update(ContractorEntity contractorEntity)
        {
            _contractorDataAccess = new ContractorDataAccess();
            if (_contractorDataAccess.Update(contractorEntity))
            {
                return true;
            }
            ErrorMessage = _contractorDataAccess.ErrorMessage;
            return false;
        }

        /// <summary>
        /// Function Delete Contractor
        /// Author: Group2.DucDM
        /// </summary>
        /// <param name="contractorEntity"></param>
        /// <returns></returns>
        public static bool Delete(ContractorEntity contractorEntity)
        {
            _contractorDataAccess = new ContractorDataAccess();
            if (_contractorDataAccess.Delete(contractorEntity))
            {
                return true;
            }
            ErrorMessage = _contractorDataAccess.ErrorMessage;
            return false;
        }
    }
}
